package hot_100;

public class 反转链表 {
    public static void main(String[] args) {

    }

    public ListNode reverseList(ListNode head) {
        ListNode before = null;
        ListNode now = head;
        while (head != null) {
            now = head;
            head = head.next;
            now.next = before;
            before = now;
        }
        return before;
    }

    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}
